package kgame5.k3d.core.camera {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;

/**
 * @author kangkai
 * 这个可由鼠标拖动
 */
public class DebugCameraBee extends CameraBee {
	
	private var mc_debug : Sprite;//专为响应滚轮事件而做的

	private var startPoint : Point;
	private var startPan:int;
	private var startY:int;

	public function DebugCameraBee(mc_debug : Sprite) {
		
		this.mc_debug = mc_debug;
		
		//mc_debug.opaqueBackground=true;
		setupEvents();
		//checkStageReady();
	}

	override public function Update() : void {
		super.Update();
	}

	
//	private function checkStageReady() : void {
//		if(view3D.stage == null) {
//			view3D.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
//		} else {
//			setupEvents();
//		}
//	}

	
//	private function onAddedToStage(event : Event) : void {
//		setupEvents();
//	}

	private function setupEvents() : void {
		mc_debug.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
		mc_debug.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		mc_debug.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
	}

	private function onMouseWheel(e:MouseEvent):void{
		radius+=-e.delta*4;
	}
	
	private function onMouseDown(event : MouseEvent) : void {
		mc_debug.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		startPoint = new Point(mc_debug.mouseX, mc_debug.mouseY);
		startPan=pan;
		startY=y;
	}

	private function onMouseUp(event : MouseEvent) : void {
		mc_debug.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
	}	

	private function onMouseMove(event : MouseEvent) : void {
		pan = startPan - (startPoint.x - mc_debug.mouseX);
		y = startY + (startPoint.y - mc_debug.mouseY);
	}	
}
}
